package nangnur.androidrumahsakit;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListAdapter extends BaseAdapter {

	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater = null;
	public ImageLoader imageLoader;

	public ListAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		imageLoader = new ImageLoader(activity.getApplicationContext());
	}

	public int getCount() {
		return data.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.item_list_rs, null);

		TextView id_rs = (TextView) vi.findViewById(R.id.id_rs); 
		TextView nama_rs = (TextView) vi.findViewById(R.id.nama_rs); 
		TextView link_image_rs = (TextView) vi.findViewById(R.id.link_image_rs);
		TextView alamat_rs = (TextView) vi.findViewById(R.id.alamat_rs); 
		TextView telepon_rs = (TextView) vi.findViewById(R.id.telepon_rs);
		ImageView thumb_image = (ImageView) vi.findViewById(R.id.image_rs); 
		
		HashMap<String, String> daftar_rs = new HashMap<String, String>();
		daftar_rs = data.get(position);
	
		id_rs.setText(daftar_rs.get(MainActivity.TAG_ID_RS));
		nama_rs.setText(daftar_rs.get(MainActivity.TAG_NAMA_RS));
		link_image_rs.setText(daftar_rs.get(MainActivity.TAG_LINK_IMAGE_RS));
		alamat_rs.setText(daftar_rs.get(MainActivity.TAG_ALAMAT_RS));
		telepon_rs.setText(daftar_rs.get(MainActivity.TAG_TELEPON_RS));
		imageLoader.DisplayImage(daftar_rs.get(MainActivity.TAG_LINK_IMAGE_RS),
				thumb_image);
		return vi;
	}
}